package site.shader85.Kingdoms.domain;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;

import site.shader85.Kingdoms.KingdomsPlugin;

public class DomainConfig extends YamlConfiguration {

	File f;

	public DomainConfig(KingdomsPlugin plugin){
		f = new File(plugin.getDataFolder(),"domains.yml");
		if(!f.exists())
			plugin.saveResource("domains.yml", false);
		try {
			this.load(f);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InvalidConfigurationException e) {
			e.printStackTrace();
		}
	}
	
	public void setDomain(Domain d){
		this.set(d.getName(), d);
		save();
	}
	
	public Domain getDomain(String path) {
		Object obj = this.get(path);
		return obj == null ? null : (Domain) obj;
	}
	
	public void save(){
		try {
			this.save(f);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
